<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加预约</title>
</head>
<body>
<form class="user" name="bookTimeAdd" method="post" th:action="@{/bookTime/add}" th:object="${bookTime}">
    <input type="hidden" id="id" name="id" th:value="${bookTime?.id}">
    <div >
        <div >
            所属医院：
            <select name="hospitalId" id="hospitalId" onchange="getDeparment(this);">
                <option value="">--选择医院--</option>
                <option th:each="oo : ${hospitals}" th:value="${oo.id}" th:text="${oo.hospitalName}" th:selected="${hospital?.hospitalName}==${oo.hospitalName}">value</option>
            </select>
        </div>
        <div >
            所属科室：
            <select name="departmentId" id="departmentId" onchange="getDoctor(this);">
            </select>
        </div>
        <div >
            医生：
            <select name="doctorId" id="doctorId">
            </select>
        </div>
        <div >
            时间段：
            <input type="text"  th:field="*{fromTo}" placeholder="时间段">
        </div>
    </div>
    <input type="submit" value="添加/修改" class="btn btn-success" >
</form>

<script type="text/javascript" th:src="@{/js/jquery.js}"></script>

<script type="text/javascript">
    function getDeparment(obj) {
            $.post("/department/getDepartment", {"hid": $(obj).val()}, function (data) {
                if (data) {
                    $("#departmentId" ).html('');
                    $("#departmentId").append("<option value=''>--选择科室--</option>");
                    $("#departmentId").val('');
                    $.each(data, function (i, v) {
                        $("#departmentId").append("<option value='" + v.id + "'>" + v.name + "</option>");
                    });

                }
            }, "json");
        }
    function getDoctor(obj) {
        $.post("/department/getDoctor", {"did": $(obj).val()}, function (data) {
            if (data) {
                $("#doctorId" ).html('');
                $("#doctorId").append("<option value=''>--选择医生--</option>");
                $("#doctorId").val('');
                $.each(data, function (i, v) {
                    $("#doctorId").append("<option value='" + v.id + "'>" + v.name + "</option>");
                });

            }
        }, "json");
    }
</script>

</body>
</html>